<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class User extends Model {

	protected $table = 'users';

	protected $fillable = array('mobile', 'password', 'type', 'children_name', 'birthday', 'status');

	protected $hidden = ['password','adminid','last_get_notify_time'];
        
        public function publicProfile($user_id) {
            if (!$user = $this->select('id', 'mobile','children_name', 'address_id', 'city', 'gender', 'birthday', 'avatar', 'cover','total_fans')->where('status', '1')->find($user_id)) {
                return false;
            }
            if (!$user->children_name) {
                $user->children_name = preg_replace('/(1[358]{1}[0-9])[0-9]{4}([0-9]{4})/i', '$1****$2', $user->mobile);
            } else {
                unset($user->mobile);
            }
            return $user;
        }
        public function getUserById($user_id) {
            if (!$user = $this->where('status', '1')->find($user_id)) {
                return false;
            }
            return $user;
        }
}